<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	cfc('core')->checklogin();
	if(!$_RQ['id']){
		exi('没有找到该题库，请重新选择！','error','jy_lineks/index/');
	}
	$item=pdo_get('jy_lineks_tiku_zu',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'zu_id'=>$_RQ['id']);
	$return['cards']=pdo_getall('jy_lineks_cuo',$params,array('id'));
	$return['allnum']=count($return['cards']);
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['remark'],
		'link'=>custom_url('jy_lineks/cuo_ti/',true),
		'imgUrl'=>ATTACHMENT_URL.$item['image'],
	);
	set_html('title',$item['title']);
	$this->session('zu_id',$_RQ['id']);
	$return['params']=array('page'=>1);
	$return['danan_key']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'zu_id'=>$this->session('zu_id'));
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 1;
	}
	$total='';
	$list=pdo_getslice('jy_lineks_cuo',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$v){
			$v=pdo_get('jy_lineks_tiku',array('id'=>$v['ti_id']));
			$v['xuanxiang']=json_decode($v['xuanxiang'],true);
			$v['images']=json_decode($v['images'],true);
			$like=pdo_get('jy_lineks_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$v['id']),'id');
			$v['islike']=$like['id']?1:0;
			$v['typetitle']=$this->ti_types[$v['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='update'){
	$postdata=get_postdata();
	if($postdata){
		$isadd=pdo_get('jy_lineks_cuo',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$postdata['id']),'id');
		if(!$isadd['id']){
			$insert=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$_SESSION['uid'],
					'ti_id'=>$postdata['id'],
					'zu_id'=>$this->session('zu_id'),
					'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_lineks_cuo',$insert);
		}
	}
	exi('success');
}
